<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/png" href="${baseUrl}img/favicon.ico">
    <title>登录</title>
    <!--  url:   -->
    <link href="${baseUrl}css/bootstrap.min.css" rel="stylesheet">
    <link href="${baseUrl}font-awesome/css/font-awesome.css" rel="stylesheet">
    <link href="${baseUrl}css/animate.css" rel="stylesheet">
    <link href="${baseUrl}css/style.css" rel="stylesheet">
    <script type="text/javascript" src="${baseUrl}js/jquery-2.1.1.js"></script>
    <!-- Sweet alert -->
    <link href="${baseUrl}css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="${baseUrl}js/plugins/sweetalert/sweetalert.min.js"></script>
</head>
<body class="gray-bg">

<div class="loginColumns animated fadeInDown">
    <div class="row">
        <div class="col-md-6">
            <img src="${baseUrl}img/login_logo.png" class="img-responsive" alt="logo">
        </div>
        <div class="col-md-6">
            <div class="ibox-content">
                <form class="m-t" role="form" action="${baseUrl}system/to_index">
                    <div class="form-group">
                        <input type="text" id="userName" class="form-control" placeholder="用户名或手机号">
                    </div>
                    <div class="form-group">
                        <input type="password" id="userPwd" class="form-control" placeholder="密码">
                    </div>
                    <button id="login" type="button" class="btn btn-primary block full-width m-b">登 录</button>
                </form>

                <address class="m-t project-people">
                    <small>如需开通账号或相关权限，请邮件给</small>
                    <br>
                    <strong>Enonliu刘义楠</strong><br>
                    <a href="mailto:Enonliu#heatup.cn">Enonliu#heatup.cn</a>
                </address>
            </div>
        </div>
    </div>
    <hr/>
    <div class="row">
        <div class="col-md-6">
            深圳市游方互动科技有限公司<br>Shenzhen YouFun Interactive Technolgy Consultancy co.Ltd
        </div>
        <div class="col-md-6 text-right">
            <small>© 2016</small>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#login").click(function () {
            var userName = Trim($("#userName").val(), 'g');
            var userPwd = Trim($("#userPwd").val(), 'g');
            if (userName == '') {
                swal('', "用户名或手机号不能为空", 'warning');
                $("#userName").focus();
                return;
            }
            if (userPwd == '') {
                swal('', "密码不能为空", 'warning');
                $("#userPwd").focus();
                return;
            }
//            $.ajax({
//                url: "${baseUrl}system/pre/login?userName=" + userName + "&userPwd=" + userPwd,
//                type: "POST",
//                success: function (result) {
//                    console.log(result);
//                    debugger
//                    if (result.data.code == 0) {
//                        alert(result.data.msg);
//                        $("#userName").focus();
//                    } else if (result.data && result.data.data && result.data.data.returnUrl) {
//                        //如果有登陆前的URL则直接跳转
//                        window.location = result.data.data.returnUrl;
//                    } else {
//                        window.location = "${baseUrl}system/to_index";
//                    }
//                }
//            });
            var params = {
                userName: userName,
                userPwd: userPwd,
                returnUrl: window.location.search.substring(12)
            };
            $.post("${baseUrl}system/pre/login", params, function (result) {
                console.log(result);
                debugger;
                if (result.data.code === 0) {
                    swal('', result.data.msg, 'error');
                    $("#userName").focus();
                } else if (result.data && result.data.data && result.data.data.returnUrl) {
                    //如果有登陆前的URL则直接跳转
                    window.location = result.data.data.returnUrl;
                } else {
                    window.location = "${baseUrl}system/to_index";
                }
            });
        });
        $(document).keypress(function (e) {
            // 回车键事件
            if (e.which === 13) {
                $("#login").click();
            }
        });
    });

    function Trim(str, is_global) {
        var result;
        result = str.replace(/(^\s+)|(\s+$)/g, "");
        if (is_global.toLowerCase() == "g")
            result = result.replace(/\s/g, "");
        return result;
    }
</script>
</body>

</html>